package implementation.client.net;

import implementation.shared.IPacket;

import java.util.Queue;
import java.util.logging.Logger;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

public class ClientChannelHandler extends SimpleChannelUpstreamHandler{
	
	private final Queue<IPacket> _messageQueue;
	
	public ClientChannelHandler(Queue<IPacket> messageQueue) {
		super();
		this._messageQueue = messageQueue;
	}
	
	@Override
	public void messageReceived(ChannelHandlerContext context, MessageEvent e) {
		
		IPacket msg = (IPacket) e.getMessage();
		
		this._messageQueue.add(msg);
		synchronized (this._messageQueue) {
			this._messageQueue.notify();
		}
		
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext context, ExceptionEvent e) {
		//this._logger.log(Level.WARNING, "channel handler exception", e.getCause());
	}
		
}
